package com.daiyang.campus_lucky_draw.mapper;

import com.daiyang.campus_lucky_draw.mapper.DO.ActivityPrizeDO;
import jakarta.validation.constraints.NotNull;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface ActivityPrizeMapper {
    @Insert("<script>"
            + " insert into activity_prize(activity_id, prize_id, prize_amount, prize_tiers, status)"
            + " values <foreach collection='items' item='item' index='index' separator=','>"
            + " (#{item.activityId}, #{item.prizeId}, #{item.prizeAmount}, #{item.prizeTiers}, #{item.status})"
            + " </foreach>"
            + " </script>")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    int batchInsert(@Param("items") List<ActivityPrizeDO> activityPrizeDOList);

    @Select("select * from activity_prize where activity_id = #{activityId}")
    List<ActivityPrizeDO> selectByActivityId(@Param("activityId") Long activityId);
    /**
     * 根据活动id和奖品id查询活动奖品
     * @param activityId 活动id
     * @param prizeId 奖品id
     * @return 活动奖品
     */
    @Select("select * from activity_prize where activity_id = #{activityId} and prize_id = #{prizeId}")
    ActivityPrizeDO selectByActivityIdAndAPrizeId(@NotNull(message = "活动id不能为空！") Long activityId, @NotNull(message = "奖品id不能为空！") Long prizeId);

    @Select("select count(1) from activity_prize where activity_id = #{activityId} and status = #{status}")
    int countPrize(@Param("activityId") Long activityId, @Param("status") String status);

    @Select("select * from activity_prize where activity_id = #{activityId} and prize_id = #{prizeId}")
    ActivityPrizeDO selectByAPId(@Param("activityId") Long activtyId, @Param("prizeId") Long prizeId);

    @Update("update activity_prize set status = #{status} where activity_id = #{activityId} and prize_id = #{prizeId}")
    void updateStatus(@Param("activityId") Long activityId,
                      @Param("prizeId") Long prizeId,
                      @Param("status") String status);

}
